home *** CD-ROM | disk | FTP | other *** search
Java Source | 2002-03-28 | 2.9 KB | 123 lines |
- // ------------------------------------------------------------------
- //
- // Purpose.............: Url
- // Created.............: May 8, 2001
- // Copyright...........: (c) 2001 by Adobe Systems
- //
- // ------------------------------------------------------------------
-
- import java.io.*;
- import java.util.ResourceBundle;
- import java.util.Locale;
- import java.net.URLDecoder;
-
- /**
- * This class stores the detail information for UrlList class.
- * For example:
- * <pre>
- * Url url = new Url();
- * url.setUrl("http://www.adobe.com");
- * </pre>
- *
- * @author Adobe Systems, Inc.
- * @since 1.0
- */
- public class Url {
-
- /** It stores URL string with URL parameter. It is same as in the URL list file. */
- public String url;
-
- /** It stores URL string as URL decoded. */
- public String decodedUrl;
-
- /** It stores each directory name in the URL. */
- public String[] dir;
-
- /** It stores how many level of dir. */
- public int level;
-
- /** It stores saving filename specified in URL list file. */
- public String filename;
-
- /** It stores just URL parameter part from URL. */
- public String parameter;
-
- /**
- * Initialize
- * @param void
- * @return void
- */
- public Url() {
- url = "";
- dir = new String[50];
- level = 0;
- filename = "";
- parameter = "";
- }
-
- /**
- * Set URL
- * @param fullUrl
- * @return void
- */
- public void setUrl(String fullUrl) {
- url = fullUrl;
- try {
- decodedUrl = URLDecoder.decode(fullUrl);
- } catch(Exception e) {
- e.printStackTrace();
- }
-
- int index = 0;
- for (int i = 0; i < 3; i++) {
- if (-1 == (index = fullUrl.indexOf('/', index+1))) {
- ResourceBundle rb = ResourceBundle.getBundle("PageGenerator");
- System.err.println(rb.getString("unexpectedError"));
- return;
- }
- }
- dir[level++] = fullUrl.substring(0, index);
- for (int i = index+1; i < fullUrl.length(); i++) {
- if (-1 == (index = fullUrl.indexOf('/', i))) {
- if (-1 == (index = fullUrl.indexOf('?', i))) {
- filename = fullUrl.substring(i);
- } else {
- filename = fullUrl.substring(i, index);
- parameter = fullUrl.substring(index);
- }
- break;
- } else {
- dir[level++] = fullUrl.substring(i, index);
- i = index;
- }
- }
- return;
- }
-
- /**
- * Display class variables
- * @param void
- * @return void
- */
- public void print() {
- System.out.println("url = [" + url + "]");
- System.out.println("decodedUrl= [" + decodedUrl + "]");
- System.out.println("level = [" + level + "]");
- for (int i = 0; i < level; i++) {
- System.out.println("dir[" + i + "] = [" + dir[i] + "]");
- }
- System.out.println("filename = [" + filename + "]");
- System.out.println("parameter = [" + parameter + "]");
- }
-
- /**
- * Display string
- * @param s Strings to display
- * @return void
- */
- private static void print(String s) {
- System.out.println(s);
- }
- }
-
-